<!--对账情况报表-->
<template>
	<div class="m-view-accountReport m-window" v-loading="loading">
		<div class="m-condition">
			<el-row :gutter="10">
				<el-form
					:model="searchForm"
					ref="headerRuleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="7">
						<el-form-item label="公司" class="rightItem">
							<el-select
								value-key="id"
								v-model="searchForm.companyCode"
								placeholder="请选择公司"
								@change="companyChange"
								ref="content"
								filterable
							>
								<el-option
									v-for="item in comOptions"
									:key="item.id"
									:label="item.companyName"
									:value="item.companyCode"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="5">
						<el-form-item label="对账日期" class="rightItem">
							<el-date-picker
								v-model="searchForm.startDate"
								type="date"
								:placeholder="placeholder.start"
								value-format="yyyy-MM-dd"
								:picker-options="stOptions"
								:editable="false"
								:clearable="false"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="4">
						<el-date-picker
							v-model="searchForm.endDate"
							type="date"
							:placeholder="placeholder.end"
							value-format="yyyy-MM-dd"
							:picker-options="etOptions"
							:editable="false"
							:clearable="false"
						></el-date-picker>
					</el-col>
				</el-form>
				<el-col :span="2" :offset="6">
					<el-button type="primary" @click="searchReport(1)" :disabled="btnDis">查询</el-button>
				</el-col>
			</el-row>
		</div>
		<div class="m-content">
			<!-- 实物对账报表 -->
			<div class="m-report-content">
				<el-row class="m-reportPanel" :gutter="10">
					<el-col class="m-chart" :span="8">
						<span class="m-title">实物对账</span>
						<chart
							:options="chartOptions"
							:id="'goodsChart'"
							:height="'100%'"
							ref="goodsChart"
							:width="'100%'"
							@chartClick="chartClick"
						></chart>
					</el-col>
					<el-col :span="16">
						<span class="m-title">{{`${goodsRight.title} ${goodsRight.count}`}}</span>
						<div class="m-table-content">
							<div class="m-agTable m-bottom m-top2" :style="{'top':'0'}">
								<agGridComponents
									ref="goodsBillsGrid"
									:getGridOptions="supplierGridOptions"
									:getColumnDefs="supplierColumnDefs"
								></agGridComponents>
							</div>
							<div class="m-page">
								<el-pagination
									@size-change="handleSizeChange($event,'goods')"
									@current-change="handleCurrentChange($event,'goods')"
									@prev-click="handlePrevClick($event,'goods')"
									@next-click="handleNextClick($event,'goods')"
									:current-page="pageInfo.current"
									:page-sizes="[10,30,50,100,150]"
									:page-size="pageInfo.size"
									layout="total, sizes, prev, pager, next, jumper"
									:total="pageInfo.total"
								></el-pagination>
							</div>
						</div>
					</el-col>
				</el-row>
			</div>
			<!-- 会计对账报表 -->
			<div class="m-report-content" style="margin-top:10px">
				<el-row class="m-reportPanel" :gutter="10">
					<el-col class="m-chart" :span="8">
						<span class="m-title">会计对账</span>
						<chart
							:options="accountChartOptions"
							:id="'accountChart'"
							:height="'100%'"
							:width="'100%'"
							@chartClick="chartClick"
						></chart>
					</el-col>
					<el-col :span="16">
						<span class="m-title">{{`${accountRight.title} ${accountRight.count}`}}</span>
						<div class="m-table-content">
							<div class="m-agTable m-bottom m-top2" :style="{'top':'0'}">
								<agGridComponents
									ref="accountBillsGrid"
									:getGridOptions="billsGridOptions"
									:getColumnDefs="supplierColumnDefs"
								></agGridComponents>
							</div>
							<div class="m-page">
								<el-pagination
									@size-change="handleSizeChange($event,'account')"
									@current-change="handleCurrentChange($event,'account')"
									@prev-click="handlePrevClick($event,'account')"
									@next-click="handleNextClick($event,'account')"
									:current-page="accountPage.current"
									:page-sizes="[10,30,50,100,150]"
									:page-size="accountPage.size"
									layout="total, sizes, prev, pager, next, jumper"
									:total="accountPage.total"
								></el-pagination>
							</div>
						</div>
					</el-col>
				</el-row>
			</div>
		</div>
	</div>
</template>

<script>
import _Api from "@/api";
import constant from "@/public/constant";
import serviceTime from "@/public/serverTime.js";
import Chart from "@/components/eCharts";
import agGridComponents from "@/components/agGridComponents.js"
import Msg from "@/public/message.js";
import waterfall from 'async-es/waterfall';
import { exportExcel } from 'lesso-common/public/utils';


export default {
	data () {
		return {
			btnDis: false,
			loading: false,
			goodsRight: {
				title: '',
				count: ''
			},
			accountRight: {
				title: '',
				count: ''
			},
			// 查询条件   
			searchForm: {
				companyCode: '',
				startDate: '',
				endDate: '',
				companyName: ''
			},
			// 实物对账右侧列表分页信息   
			pageInfo: {
				current: 1,
				size: 10,
				total: 0
			},
			// 会计对账右侧列表分页信息   
			accountPage: {
				current: 1,
				size: 10,
				total: 0
			},
			// 开始日期范围限制   
			stOptions: {
				disabledDate: this.disabledStartDate
			},
			// 结束日期范围限制  
			etOptions: {
				disabledDate: this.disabledEndDate
			},
			// 实物对账列表查询参数  
			chartParams: {},
			// 会计对账列表查询参数  
			accountParams: {},
			// 公司下拉内容
			comOptions: [],
			//实物对账图表配置
			chartOptions: {},
			//会计对账图表配置
			accountChartOptions: {},
			supplierGridOptions: {},
			supplierColumnDefs: [],
			billsGridOptions: {},
			// 日期控件默认值 
			placeholder: {
				start: '',
				end: ''
			}
		};
	},
	beforeMount () {
		// 供应商表格配置
		this.supplierGridOptions = {
			suppressContextMenu: false,
			getContextMenuItems: this.getContextMenuItems
		}
		// 单据表格配置
		this.billsGridOptions = {
			suppressContextMenu: false,
			getContextMenuItems: this.getContextMenuItems
		}
		//   供应商表格列配置
		this.supplierColumnDefs = [
			{ headerName: "公司", field: "companyCode", width: 70 },
			{ headerName: "公司名称", field: "companyName", width: 120 },
			{ headerName: "供应商", field: "supplierCode", width: 100 },
			{ headerName: "供应商名称", field: "supplierName", width: 120 },
			{ headerName: "对账单", field: "quantity", width: 80 },
			{ headerName: "对账金额", field: "amount", width: 100 },
		]
		// 对账单据表格列配置
		this.billsColumnDefs = [
			{ headerName: "公司", field: "companyCode", width: 70 },
			{ headerName: "公司名称", field: "companyName", width: 120 },
			{ headerName: "供应商", field: "supplierCode", width: 100 },
			{ headerName: "供应商名称", field: "supplierName", width: 120 },
			{ headerName: "对账单号", field: "accountNo", width: 100 },
			{
				headerName: "单据日期",
				field: "createDate",
				width: 100,
				cellRenderer: function (params) {
					if (params.value)
						return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format("yyyy-MM-dd");
				}
			},
			{ headerName: "对账金额", field: "amount", width: 100 },
			{
				headerName: "状态",
				field: "billState",
				width: 70,
				cellRenderer: function (params) {
					if (params.value == "1")
						return '<span class="ag-icon">已保存</span>';
					else if (params.value == "2")
						return '<span class="ag-icon">已提交</span>';
					else if (params.value == "3")
						return '<span class="ag-icon">已确认</span>';
					else if (params.value == "4")
						return '<span class="ag-icon">已审核</span>';
				}
			},
			{ headerName: "应付人员", field: "confirmer", width: 100, type: ['textColumn'] },
		]
	},
	mounted () {
		this.initDataFunc()
	},
	components: {
		Chart,
		agGridComponents
	},
	methods: {
		//  限制开始日期选择范围
		disabledStartDate (time) {
			const { endDate } = this.searchForm
			if (endDate)
				return time.getTime() > new Date(endDate).getTime();
		},
		//  限制结束日期选择范围
		disabledEndDate (time) {
			const { startDate } = this.searchForm
			if (startDate)
				return time.getTime() < (new Date(startDate).getTime() - 3600 * 1000 * 24)
		},
		// 查询对账报表
		searchReport (flag) {
			if (flag) {
				this.$refs.goodsBillsGrid.gridOptions.api.setColumnDefs(this.supplierColumnDefs)
				this.$refs.accountBillsGrid.gridOptions.api.setColumnDefs(this.supplierColumnDefs)
				this.pageInfo.current = 1
				this.accountPage.current = 1
			}
			const { companyCode, startDate, endDate } = this.searchForm
			let parmas = {
				companyCode,
				createSt: startDate,
				createEt: endDate
			}
			let tablePramas = {
				...parmas,
				current: 1,
				size: 10,
				flag: 1,
				isRecony: true
			}
			this.chartParams = {
				...parmas,
				flag: 1,
				isRecony: true
			}
			this.accountParams = {
				...parmas,
				flag: 1,
				isRecony: true
			}
			let searchGoods = new Promise((resolve, reject) => {
				_Api.getGoodsBills(parmas).then((res) => {
					let data = res.data
					if (data.code == 1) {
						resolve(data.rows)
					} else {
						reject(data.info)
					}
				})
					.catch((err) => {
						reject(err.data.message)
					})
			})
			let searchAccount = new Promise((resolve, reject) => {
				_Api.getAccountBills(parmas).then((res) => {
					let data = res.data
					if (data.code == 1) {
						resolve(data.rows)
					} else {
						reject(data.info)
					}
				})
					.catch((err) => {
						reject(err.data.message)
					})
			})
			let getAccountBills = this.getAccountBillsDetail(tablePramas)
			let getGoodsBills = this.getGoodsBillsDetail(tablePramas)
			this.loading = true
			Promise.all([searchGoods, searchAccount, getAccountBills, getGoodsBills]).then((result) => {
				this.loading = false
				if (result.length > 0) {
					this.setChartData(result)
				}
			}).catch((error) => {
				Msg.showErrorMsg(error)
			})
		},
		// 每页显示条数改变回调
		handleSizeChange (pra, val) {
			if (val == 'goods') {
				this.pageInfo.size = pra
				this.pageInfo.current = 1
				this.getGoodsBillsDetail(this.chartParams).then((rows) => {
					this.$refs.goodsBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			} else {
				this.accountPage.size = pra
				this.accountPage.current = 1
				this.getAccountBillsDetail(this.accountParams).then((rows) => {
					this.$refs.accountBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			}
		},
		// 页码改变回调
		handleCurrentChange (pra, val) {
			if (val == 'goods') {
				this.pageInfo.current = pra
				this.getGoodsBillsDetail(this.chartParams).then((rows) => {
					this.$refs.goodsBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			} else {
				this.accountPage.current = pra
				this.getAccountBillsDetail(this.accountParams).then((rows) => {
					this.$refs.accountBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			}
		},
		//  点击上一页回调
		handlePrevClick (pra, val) {
			if (val == 'goods') {
				this.pageInfo.current = pra
			} else {
				this.accountPage.current = pra
			}
		},
		//  点击下一页回调
		handleNextClick (pra, val) {
			if (val == 'goods') {
				this.pageInfo.current = pra
			} else {
				this.accountPage.current = pra
			}
		},
		// 初始化图表和表格数据
		setChartData (res) {
			const { confirmAmount, newAmount, reconciledAmount, submitAmount, unReconciledAmount } = res[0]
			//   实物对账图表配置
			this.chartOptions = {
				tooltip: {
					trigger: 'item',
					formatter: "{a} <br/>{b}: {c} ({d})%"
				},
				series: [
					{
						name: '实物对账单统计(份)',
						type: 'pie',
						selectedMode: 'single',
						radius: [0, '30%'],
						id: 'goodsPie1',
						label: {
							normal: {
								position: 'inner'
							}
						},
						labelLine: {
							normal: {
								show: false
							}
						},
						data: [
							{
								value: reconciledAmount,
								name: `已对账:${reconciledAmount}`,
								title: '已对账',
								selected: true,
								isRecony: true,
								flag: 1							},
							{
								value: unReconciledAmount,
								name: `未对账:${unReconciledAmount}`,
								title: '未对账',
								isRecony: false,
								flag: 1							}
						]
					},
					{
						name: '实物对账单统计(份)',
						type: 'pie',
						radius: ['45%', '60%'],
						id: 'goodsPie2',
						label: {
							normal: {
							}
						},
						data: [
							{ value: newAmount, name: '已保存', flag: 2, billState: 1 },
							{ value: confirmAmount, name: '已确认', flag: 2, billState: 3 },
							{ value: submitAmount, name: '已提交', flag: 2, billState: 2 }
						]
					}
				]
			}
			// 实物对账右侧表格抬头数据  
			this.goodsRight = {
				title: `已对账供应商:`,
				count: `${reconciledAmount}个`
			}
			// 会计对账图表配置  
			this.accountChartOptions = {
				tooltip: {
					trigger: 'item',
					formatter: "{a} <br/>{b}: {c} ({d})%"
				},
				series: [
					{
						name: '会计对账单统计(份)',
						type: 'pie',
						selectedMode: 'single',
						radius: [0, '30%'],
						id: 'accountPie1',
						label: {
							normal: {
								position: 'inner'
							}
						},
						labelLine: {
							normal: {
								show: false
							}
						},
						data: [
							{
								value: res[1].reconciledAmount,
								name: `已对账:${res[1].reconciledAmount}`,
								title: '已对账',
								selected: true,
								isRecony: true,
								flag: 1
							},
							{
								value: res[1].unReconciledAmount,
								name: `未对账:${res[1].unReconciledAmount}`,
								title: '未对账',
								isRecony: false,
								flag: 1							}
						]
					},
					{
						name: '会计对账单统计(份)',
						type: 'pie',
						radius: ['45%', '60%'],
						id: 'accountPie2',
						label: {
							normal: {
							}
						},
						data: [
							{ value: res[1].newAmount, name: '已保存', billState: 1, flag: 2 },
							{ value: res[1].submitAmount, name: '已提交', billState: 2, flag: 2 },
							{ value: res[1].confirmAmount, name: '已确认', billState: 3, flag: 2 },
							{ value: res[1].reviewAmount, name: '已审核', billState: 4, flag: 2 },
						]
					}
				]
			}
			// 会计对账右侧表格抬头数据 
			this.accountRight = {
				title: `已对账供应商:`,
				count: `${res[1].reconciledAmount}个`
			}
			this.$refs.goodsBillsGrid.gridOptions.api.setRowData(res[3])
			this.$refs.accountBillsGrid.gridOptions.api.setRowData(res[2])
		},
		companyChange (val) {
			this.comOptions.forEach(item => {
				if (item.companyCode == val) {
					this.searchForm.companyName = item.companyName
				}
			})
		},
		// 点击统计图表事件总线
		chartClick (parmas) {
			let reportData = parmas.data
			const { companyCode, startDate, endDate } = this.searchForm
			const { flag, name, value, title } = reportData
			let obj = {
				companyCode, //公司编码
				createSt: startDate, // 对账开始日期
				createEt: endDate,// 对账结束日期
				flag //1、查询对账列表；2、查询单据列表
			}

			// 实物对账单列表信息
			if (parmas.seriesId == "goodsPie1") {
				if (this.pageInfo.current != 1) this.pageInfo.current = 1
				this.$refs.goodsBillsGrid.gridOptions.api.setColumnDefs(this.supplierColumnDefs)
				this.goodsRight = {
					title: `${title}供应商:`,
					count: `${value}个`
				}
				obj.isRecony = reportData.isRecony
				this.chartParams = obj
				this.getGoodsBillsDetail(obj).then((rows) => {
					this.$refs.goodsBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			} else if (parmas.seriesId == "goodsPie2") {
				if (this.pageInfo.current != 1) this.pageInfo.current = 1
				let colDef = { headerName: "对账单号", field: "gooAccNo", width: 100 }
				this.billsColumnDefs.splice(4, 1, colDef)
				this.$refs.goodsBillsGrid.gridOptions.api.setColumnDefs(this.billsColumnDefs)
				this.goodsRight = {
					title: `${name}单据:`,
					count: `${value}个`
				}
				obj.billState = reportData.billState
				this.chartParams = obj
				this.getGoodsBillsDetail(obj).then((rows) => {
					this.$refs.goodsBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			}
			// 会计对账单列表信息
			if (parmas.seriesId == "accountPie1") {
				if (this.accountPage.current != 1) this.accountPage.current = 1
				this.$refs.accountBillsGrid.gridOptions.api.setColumnDefs(this.supplierColumnDefs)
				this.accountRight = {
					title: `${title}供应商:`,
					count: `${value}个`
				}
				obj.isRecony = reportData.isRecony
				this.accountParams = obj
				this.getAccountBillsDetail(obj).then((rows) => {
					this.$refs.accountBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			} else if (parmas.seriesId == "accountPie2") {
				if (this.accountPage.current != 1) this.accountPage.current = 1
				let colDef = { headerName: "对账单号", field: "accountNo", width: 100 }
				this.billsColumnDefs.splice(4, 1, colDef)
				this.$refs.accountBillsGrid.gridOptions.api.setColumnDefs(this.billsColumnDefs)
				this.accountRight = {
					title: `${name}单据:`,
					count: `${value}个`
				}
				obj.billState = reportData.billState
				this.accountParams = obj
				this.getAccountBillsDetail(obj).then((rows) => {
					this.$refs.accountBillsGrid.gridOptions.api.setRowData(rows)
				}).catch(err => {
					Msg.showErrorMsg(err)
				})
			}
		},
		// 调接口获取实物对账统计详情信息
		getGoodsBillsDetail (obj, pageSize) {
			const { current, size } = this.pageInfo
			const { companyCode, companyName } = this.searchForm
			console.log('公司信息', companyName)
			/**
			* parmas属性说明
			* @property {string} companyCode 公司编码
			* @property {string} createSt 对账开始日期
			* @property {string} createEt 对账结束日期
			* @property {number} flag 1已对账/未对账列表；2单据列表
			* @property {Blooen} isRecony true已对账；false未对账
			* @property {number} billState 1 已保存2 已提交3 已确认
			*/
			let parmas = {
				...obj,
				current: pageSize ? 1 : current,
				size: pageSize ? pageSize : size
			}
			return new Promise((resolve, reject) => {
				this.$refs.goodsBillsGrid.loading = true
				_Api.getGoodsBillsTab(parmas).then((res) => {
					let data = res.data
					if (data.code == 1) {
						this.pageInfo.total = data.total
						this.$refs.goodsBillsGrid.loading = false
						data.rows.forEach((row) => {
							if (!row.companyName && !row.companyCode) {
								row.companyName = companyName
								row.companyCode = companyCode
							}
						})
						resolve(data.rows)
					} else {
						reject(data.info)
					}
				})
					.catch(err => {
						reject(err.data.message)
					})
			})
		},
		// 调接口获取会计对账统计列表信息
		getAccountBillsDetail (obj, pageSize) {
			const { current, size } = this.accountPage
			const { companyCode, companyName } = this.searchForm
			/**
			* parmas属性说明
			* @property {string} companyCode 公司编码
			* @property {string} createSt 对账开始日期
			* @property {string} createEt 对账结束日期
			* @property {number} flag 1已对账/未对账列表；2单据列表
			* @property {Blooen} isRecony true已对账；false未对账
			* @property {number} billState 1 已保存2 已提交3 已确认4 已审核
			*/
			let parmas = {
				...obj,
				current: pageSize ? 1 : current,
				size: pageSize ? pageSize : size
			}
			return new Promise((resolve, reject) => {
				this.$refs.accountBillsGrid.loading = true
				_Api.getAccountBillsTab(parmas).then((res) => {
					let data = res.data
					if (data.code == 1) {
						this.accountPage.total = data.total
						this.$refs.accountBillsGrid.loading = false
						data.rows.forEach((row) => {
							if (!row.companyName && !row.companyCode) {
								row.companyName = companyName
								row.companyCode = companyCode
							}
						})
						resolve(data.rows)
					} else {
						reject(data.info)
					}
				})
					.catch(err => {
						reject(err.data.message)
					})
			})
		},
		//初始化界面数据源
		getCompanyData (callback) {
			//查询公司列表
			let obj = {}
			if (constant.user.userTypeId == 4) {
				obj.account = constant.user.userName
				obj.userType = 2
			}
			else {
				obj.account = constant.user.oaNum
				obj.userType = 1
			}
			_Api.getAuthInfo(obj).then((res) => {
				let data = res.data
				if (data.code == "1") {
					this.btnDis = false
					this.comOptions = data.rows.myMstCompany
					//默认公司
					this.searchForm.companyCode = this.comOptions[0].companyCode
					this.searchForm.companyName = this.comOptions[0].companyName
					callback()
				} else {
					this.comOptions = []
					Msg.showErrorMsg(data.info)
				}
			}).catch((err) => {
				Msg.showErrorMsg(err.data.message)
				this.comOptions = []
			})
		},
		// 初始化时间
		initDate (callback) {
			// 日期范围默认30天内
			serviceTime.getServiceTime().then((serviceTime) => {
				this.searchForm.startDate = new Date(serviceTime.getTime() - 3600 * 1000 * 24 * 30).Format('yyyy-MM-dd')
				this.searchForm.endDate = serviceTime.Format("yyyy-MM-dd")
				this.placeholder.start = "开始日期"
				this.placeholder.end = "结束日期"
				callback()
			}).catch(err => {
				Msg.showErrorMsg(err)
			})
		},
		// 初始化事件集合
		initDataFunc () {
			waterfall([
				(callback) => {
					this.initDate(callback)
				},
				(callback) => {
					this.getCompanyData(callback)
				},
				(callback) => {
					this.searchReport(callback)
				},
				(err, result) => {
					console.log(err)
				}
			])
		},
		// 定义表格右键菜单
		getContextMenuItems (node) {
			let type = node.context.componentParent.tableName
			//右击菜单
			let that = this
			let result = [
				{
					name: "导出Excel",
					action: function () {
						that.exportExcel(type)
					}
				}]
			return result
		},
		// 导出表格数据
		exportExcel (type) {
			//导出设置
			if (type == 'goodsGird') {
				const { flag } = this.chartParams
				this.getGoodsBillsDetail(this.chartParams, 100000).then(rows => {
					let excelData = []
					if (flag == 1) {
						rows.forEach(row => {
							excelData.push({
								'公司': row.companyCode,
								'公司名称': row.companyName,
								'供应商': row.supplierCode,
								'供应商名称': row.supplierName,
								'对账单': row.quantity,
								'对账金额': row.amount
							})
						})
						if (excelData.length == 0) {
							this.$alert('导出的数据为空!', {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							})
							return
						}
						let params = {
							data: excelData,
							fileName: '实物对账统计表.xlsx'
						}
						exportExcel(params)
					} else if (flag == 2) {
						rows.forEach(row => {
							excelData.push({
								'公司': row.companyCode,
								'公司名称': row.companyName,
								'供应商': row.supplierCode,
								'供应商名称': row.supplierName,
								'对账单号': row.gooAccNo,
								'单据日期': row.createDate.split(' ')[0],
								'对账金额': row.amount,
								'状态': row.billState == 1 ? '已保存' : row.billState == 2 ? '已提交' : '已确认',
								'应付人员': row.confirmer,
							})
						})
						if (excelData.length == 0) {
							this.$alert('导出的数据为空!', {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							})
							return
						}
						let params = {
							data: excelData,
							fileName: '实物对账单据统计表.xlsx'
						}
						exportExcel(params)
					}
				})
			} else {
				const { flag } = this.accountParams
				this.getAccountBillsDetail(this.accountParams, 100000).then(rows => {
					let excelData = []
					if (flag == 1) {
						rows.forEach(row => {
							excelData.push({
								'公司': row.companyCode,
								'公司名称': row.companyName,
								'供应商': row.supplierCode,
								'供应商名称': row.supplierName,
								'对账单': row.quantity,
								'对账金额': row.amount
							})
						})
						if (excelData.length == 0) {
							this.$alert('导出的数据为空!', {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							})
							return
						}
						let params = {
							data: excelData,
							fileName: '会计对账统计表.xlsx'
						}
						exportExcel(params)
					} else if (flag == 2) {
						rows.forEach(row => {
							excelData.push({
								'公司': row.companyCode,
								'公司名称': row.companyName,
								'供应商': row.supplierCode,
								'供应商名称': row.supplierName,
								'对账单号': row.accountNo,
								'单据日期': row.createDate.split(' ')[0],
								'对账金额': row.amount,
								'状态': row.billState == 1 ? '已保存' : row.billState == 2 ? '已提交' : row.billState == 3 ? '已确认' : '已审核',
								'应付人员': row.confirmer,
							})
						})
						if (excelData.length == 0) {
							this.$alert('导出的数据为空!', {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							})
							return
						}
						let params = {
							data: excelData,
							fileName: '会计对账单据统计表.xlsx'
						}
						exportExcel(params)
					}
				})
			}
		}
	}
}
</script>

<style>
</style>